import com.alibaba.fastjson.JSON
import org.apache.spark.rdd.RDD
import org.apache.spark.sql.SQLContext
import org.apache.spark.sql.functions.lit
import org.apache.spark.{SparkConf, SparkContext}

/**
  * @ Auther: o2o-rd-0008
  * @ Date:   2019/11/21 13:40
  * @ Param:  ${PARAM}
  * @ Description: 
  */
object modify_yushou_toes {

  def main(args: Array[String]): Unit = {


    val conf = new SparkConf()
    conf.setAppName(s"${this.getClass.getSimpleName}")
    conf.set("spark.debug.maxToStringFields", "500")
    conf.setMaster("local[*]")
    conf.set("es.nodes", "192.168.1.157")
    conf.set("es.port", "9200")
    conf.set("cluster.name", "O2OElastic")
    conf.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
    conf.set("spark.sql.caseSensitive", "true")
    val sc = new SparkContext(conf)
    val sqlContext = new SQLContext(sc)
    sc.setLogLevel("WARN")
    sc.hadoopConfiguration.set("fs.s3a.access.key", "GAO7EO9FWKPJ8WFCQDME")
    sc.hadoopConfiguration.set("fs.s3a.secret.key", "LZ0xaHBSYKHaJ9ECDbX9f7zin79UZkXfGoNapRPL")
    sc.hadoopConfiguration.set("fs.s3a.endpoint", "https://obs.cn-north-1.myhuaweicloud.com")

    val spark = sqlContext.sparkSession


    //val output_path = s"/private/han_0025/ruyemianshuangresult/11_yushou_v2"
    val output_path = s"s3a://o2o-dataproces-group/panzonghao/modify_shuang11_ruyemianshaungresult"

    //val path3 = s"hdfs://192.168.2.188:9000/private/han_0025/ruyemianshuangsource/11_yushou_v2"
    val path3 = s"s3a://o2o-dataproces-group/panzonghao/modify_shuang11_paths"
    //val paths = s"hdfs://192.168.2.188:9000/private/han_0025/ruyemianshuangsource/11_yushou_v2"
    val paths = s"s3a://o2o-dataproces-group/panzonghao/modify_shuang11_paths"
     //  "D:\\soft\\Git\\workSpace\\month_3\\src\\main\\scala\\com\\o2o\\Tmall\\tmp\\package_4_month\\Ruye_mianshuang_2\\test"
    //val index = s"${indexs}"
   val yushou_data = sqlContext.read.orc("s3a://o2o-dataproces-group/panzonghao/modify_shuang11")
    val values: RDD[String] = yushou_data.toJSON.rdd
    values.repartition(1).saveAsTextFile(paths)
    val rdd =spark.sparkContext.textFile(paths)
    val unit = rdd.map(line => {
      val nObject = JSON.parseObject(line)
      val baser = nObject.get("Base_Info").toString
      val title = nObject.get("title").toString
      val good_id = nObject.get("good_id").toString
      var good = good_id
      var base = "-1"
      var flag = "-1"
      if (!baser.equals("-1")) {
        val basinfo = JSON.parseObject(baser)
        val set = basinfo.keySet().toArray
        var key2 = "-1"
         var key3 = "-1"
        var key4 ="-1"
        var flags = true
        var flags1=true
        var flags2=true
        for (i <- 0 to set.length - 1 if flags) {
          val key = set(i).toString
          if (key.equals("化妆品净含量")) {
            key2 = basinfo.get(key).toString
            flags = false
          }
        }
        for (i <- 0 to set.length - 1 if flags1) {
          val key = set(i).toString
          if (key.contains("品名")) {
             key3 = basinfo.get(key).toString
            flags1 = false
          }
        }
        for (i <- 0 to set.length - 1 if flags2) {
          val key = set(i).toString
          if (key.contains("单品")) {
            key4 = basinfo.get(key).toString
            flags2 = false
          }
        }
        for (i <- 0 to set.length - 1) {
          val key = set(i).toString
          if (key.equals("乳液/面霜品类") || key.equals("乳液面霜品类")) {
            val res_str = basinfo.get(key).toString
          //  println(key + "---------" + res_str)
            if (res_str.equals("面霜")) {
              good = good_id
              base = baser
              flag = "S"
            } else if (res_str.equals("乳液/面霜") || res_str.equals("其它乳液/面霜") || res_str.contains("保湿面霜")) {
              if(key3.contains("乳") && key3.contains("霜")){
                  if(title.contains("乳") && title.contains("霜")){
                    if(title.contains("g/ml") || title.contains("g/ML") || title.contains("g/mL")){
                      flag="-1"
                    }else if(title.contains("ml") || title.contains("mL") || title.contains("ML")){
                      flag="Y"
                    }else if(title.contains("g") || title.contains("G")){
                      flag="S"
                    }
                  }else if(title.contains("霜")){
                    flag="S"
                  } else if(title.contains("乳") || title.contains("液")) {
                    flag = "Y"
                  }else if (title.contains("ML") || title.contains("ml") || title.contains("mL")) {
                    flag = "Y"
                  } else if (title.contains("g") || title.contains("G")) {
                    flag = "S"
                  }
              }else if (key3.contains("霜")) {
                flag = "S"
              } else if (key3.contains("乳") || key3.contains("液")) {
                flag = "Y"
              }else if(key4.contains("乳") && key4.contains("霜")){
                if(title.contains("乳") && title.contains("霜")){
                  if(title.contains("g/ml") || title.contains("g/ML") || title.contains("g/mL")){
                    flag="-1"
                  }else if(title.contains("ml") || title.contains("mL") || title.contains("ML")){
                    flag="Y"
                  }else if(title.contains("g") || title.contains("G")){
                    flag="S"
                  }
                }else if(title.contains("霜")){
                  flag="S"
                } else if(title.contains("乳") || title.contains("液")) {
                  flag = "Y"
                }else if (title.contains("ML") || title.contains("ml") || title.contains("mL")) {
                  flag = "Y"
                } else if (title.contains("g") || title.contains("G")) {
                  flag = "S"
                }
              }else if(key4.contains("霜")){
                flag = "S"
              } else if (key4.contains("乳") || key4.contains("液")) {
                flag = "Y"
              }else if (key2.contains("g/ml") || key2.contains("g/mL")) {
                if (title.contains("乳") || title.contains("液") || title.contains("乳液")) {
                  if (title.contains("霜") || title.contains("面霜")) {
                    flag = "-1"
                  } else {
                    flag = "Y"
                  }
                } else if (title.contains("霜")) {
                  if (title.contains("乳") || title.contains("液") || title.contains("乳液")) {

                    flag = "-1"
                  } else {
                    flag = "Y"
                  }
                }else if (title.contains("g/ml") || title.contains("g/mL")) {
                  if (title.contains("乳") || title.contains("液") || title.contains("乳液")) {
                    if (title.contains("霜") || title.contains("面霜")) {
                      flag = "-1"
                    } else {
                      flag = "Y"
                    }
                  } else if (title.contains("霜")) {
                    if (title.contains("乳") || title.contains("液") || title.contains("乳液")) {
                      flag = "-1"
                    } else {
                      flag = "Y"
                    }
                  }else if(title.contains("ML") || title.contains("ml") || title.contains("mL")){
                    flag="Y"
                  }else if(title.contains("g")){
                    flag="S"
                  }
                } else if (title.contains("g") && title.contains("ml")) {
                  if (title.contains("霜")) {
                    if (title.contains("液") || title.contains("乳")) {
                      flag = "-1"
                    } else {
                      flag = "S"
                    }
                  } else if (title.contains("液") || title.contains("乳")) {
                    if (title.contains("霜")) {
                      flag = "-1"
                    } else {
                      flag = "Y"
                    }
                  }
                } else if (title.contains("g") && title.contains("mL")) {
                  if (title.contains("霜")) {
                    if (title.contains("液") || title.contains("乳")) {
                      flag = "-1"
                    } else {
                      flag = "S"
                    }
                  } else if (title.contains("液") || title.contains("乳")) {
                    if (title.contains("霜")) {
                      flag = "-1"
                    } else {
                      flag = "Y"
                    }
                  }
                } else if (title.contains("ML") || title.contains("ml") || title.contains("mL")) {
                  flag = "Y"
                } else if (title.contains("g") || title.contains("G")) {
                  flag = "S"
                }
              } else if (key2.contains("g") || key2.contains("G")) {
                flag = "S"
              } else if (key2.contains("ml") || key2.contains("mL") || key2.contains("ML")) {
                flag = "Y"
              } else if(title.contains("霜")){
                if (title.contains("液") || title.contains("乳")) {
                  if(title.contains("g/mL")|| title.contains("g/ML")){
                    flag="-1"
                  }else if(title.contains("ml") || title.contains("mL") || title.contains("ML")){
                    flag="Y"
                  }else if(title.contains("g") || title.contains("G")){
                    flag="S"
                  }
                } else {
                  flag = "S"
                }
              }else if (title.contains("液") || title.contains("乳")) {
                if (title.contains("霜")) {
                  if(title.contains("g/mL")|| title.contains("g/ML")){
                    flag="-1"
                  }else if(title.contains("ml") || title.contains("mL") || title.contains("ML")){
                    flag="Y"
                  }else if(title.contains("g") || title.contains("G")){
                    flag="S"
                  }else{
                    flag="-1"
                  }
                } else {
                  flag = "Y"
                }
              }else  if(title.contains("g") && title.contains("mL") ) {
                if (title.contains("霜")) {
                  if (title.contains("液") || title.contains("乳")) {
                    flag = "-1"
                  } else {
                    flag = "S"
                  }
                } else if (title.contains("液") || title.contains("乳")) {
                  if (title.contains("霜")) {
                    flag = "-1"
                  } else {
                    flag = "Y"
                  }
                }
              } else if (title.contains("g") && title.contains("ml")) {
                if (title.contains("霜")) {
                  if (title.contains("液") || title.contains("乳")) {
                    flag = "-1"
                  } else {
                    flag = "S"
                  }
                } else if (title.contains("液") || title.contains("乳")) {
                  if (title.contains("霜")) {
                    flag = "-1"
                  } else {
                    flag = "Y"
                  }
                }
              } else if (title.contains("霜")) {
                if (title.contains("乳") || title.contains("液")) {
                  flag = "-1"
                } else {
                  flag = "S"
                }
              } else if (title.contains("乳") || title.contains("液")) {
                if (title.contains("霜") || title.contains("面霜")) {
                  flag = "-1"
                } else {
                  flag = "Y"
                }
              }else if(title.contains("ml") || title.contains("mL") || title.contains("ML")){
                flag="S"
              }else if(title.contains("g")){
                flag="Y"
              }
            } else if (res_str.equals("乳液") || res_str.contains("液") || res_str.contains("乳液")) {
              flag = "Y"
            }else if(res_str.contains("啫喱")){
              if(key3.contains("乳") && key3.contains("霜")){
                if(title.contains("乳") && title.contains("霜")){
                  if(title.contains("g/ml") || title.contains("g/ML") || title.contains("g/mL")){
                    flag="-1"
                  }else if(title.contains("ml") || title.contains("mL") || title.contains("ML")){
                    flag="Y"
                  }else if(title.contains("g") || title.contains("G")){
                    flag="S"
                  }
                }else if(title.contains("霜")){
                  flag="S"
                } else if(title.contains("乳") || title.contains("液")) {
                  flag = "Y"
                }else if (title.contains("ML") || title.contains("ml") || title.contains("mL")) {
                  flag = "Y"
                } else if (title.contains("g") || title.contains("G")) {
                  flag = "S"
                }
              }else if (key3.contains("霜")) {
                if(title.contains("乳") && title.contains("霜")){
                  if(title.contains("g/ml") || title.contains("g/ML") || title.contains("g/mL")){
                    flag="-1"
                  }else if(title.contains("ml") || title.contains("mL") || title.contains("ML")){
                    flag="Y"
                  }else if(title.contains("g") || title.contains("G")){
                    flag="S"
                  }
                }else if(title.contains("霜")){
                  flag="S"
                } else if(title.contains("乳") || title.contains("液")) {
                  flag = "Y"
                }else if (title.contains("ML") || title.contains("ml") || title.contains("mL")) {
                  flag = "Y"
                } else if (title.contains("g") || title.contains("G")) {
                  flag = "S"
                }
              } else if (key3.contains("乳") || key3.contains("液")) {
                flag = "Y"
              }else if(key4.contains("乳") && key4.contains("霜")){
                flag="-1"
              }else if(key4.contains("霜")){
                flag = "S"
              } else if (key4.contains("乳") || key4.contains("液")) {
                flag = "Y"
              }else if (key2.contains("g/ml") || key2.contains("g/mL")) {
                if (title.contains("乳") || title.contains("液") || title.contains("乳液")) {
                  if (title.contains("霜") || title.contains("面霜")) {
                    flag = "-1"
                  } else {
                    flag = "Y"
                  }
                } else if (title.contains("霜")) {
                  if (title.contains("乳") || title.contains("液") || title.contains("乳液")) {

                    flag = "-1"
                  } else {
                    flag = "Y"
                  }
                }else if (title.contains("g/ml") || title.contains("g/mL")) {
                  if (title.contains("乳") || title.contains("液") || title.contains("乳液")) {
                    if (title.contains("霜") || title.contains("面霜")) {
                      flag = "-1"
                    } else {
                      flag = "Y"
                    }
                  } else if (title.contains("霜")) {
                    if (title.contains("乳") || title.contains("液") || title.contains("乳液")) {
                      flag = "-1"
                    } else {
                      flag = "Y"
                    }
                  }else if(title.contains("ML") || title.contains("ml") || title.contains("mL")){
                    flag="Y"
                  }else if(title.contains("g")){
                    flag="S"
                  }
                } else if (title.contains("g") && title.contains("ml")) {
                  if (title.contains("霜")) {
                    if (title.contains("液") || title.contains("乳")) {
                      flag = "-1"
                    } else {
                      flag = "S"
                    }
                  } else if (title.contains("液") || title.contains("乳")) {
                    if (title.contains("霜")) {
                      flag = "-1"
                    } else {
                      flag = "Y"
                    }
                  }
                } else if (title.contains("g") && title.contains("mL")) {
                  if (title.contains("霜")) {
                    if (title.contains("液") || title.contains("乳")) {
                      flag = "-1"
                    } else {
                      flag = "S"
                    }
                  } else if (title.contains("液") || title.contains("乳")) {
                    if (title.contains("霜")) {
                      flag = "-1"
                    } else {
                      flag = "Y"
                    }
                  }
                } else if (title.contains("ML") || title.contains("ml") || title.contains("mL")) {
                  flag = "Y"
                } else if (title.contains("g") || title.contains("G")) {
                  flag = "S"
                }
              } else if (key2.contains("g") || key2.contains("G")) {
                flag = "S"
              } else if (key2.contains("ml") || key2.contains("mL") || key2.contains("ML")) {
                flag = "Y"
              }else if(title.contains("霜")){
                if (title.contains("液") || title.contains("乳")) {
                  if(title.contains("g/mL")|| title.contains("g/ML")){
                    flag="-1"
                  }else if(title.contains("ml") || title.contains("mL")){
                    flag="Y"
                  }else if(title.contains("g") || title.contains("G")){
                    flag="S"
                  }else{
                    flag="-1"
                  }
                } else {
                  flag = "S"
                }
              }else if (title.contains("液") || title.contains("乳")) {
                if (title.contains("霜")) {
                  if(title.contains("g/mL")|| title.contains("g/ML")){
                    flag="-1"
                  }else if(title.contains("ml") || title.contains("mL")){
                    flag="Y"
                  }else if(title.contains("g") || title.contains("G")){
                    flag="S"
                  }else{
                    flag="-1"
                  }
                } else {
                  flag = "Y"
                }
              }else  if(title.contains("g") && title.contains("mL")) {
                if (title.contains("霜")) {
                  if (title.contains("液") || title.contains("乳")) {
                    flag = "-1"
                  } else {
                    flag = "S"
                  }
                } else if (title.contains("液") || title.contains("乳")) {
                  if (title.contains("霜")) {
                    flag = "-1"
                  } else {
                    flag = "Y"
                  }
                }
              } else if (title.contains("g") && title.contains("ml")) {
                if (title.contains("霜")) {
                  if (title.contains("液") || title.contains("乳")) {
                    flag = "-1"
                  } else {
                    flag = "S"
                  }
                } else if (title.contains("液") || title.contains("乳")) {
                  if (title.contains("霜")) {
                    flag = "-1"
                  } else {
                    flag = "Y"
                  }
                }
              } else if (title.contains("霜")) {
                if (title.contains("乳") || title.contains("液")) {
                  flag = "-1"
                } else {
                  flag = "S"
                }
              } else if (title.contains("乳") || title.contains("液")) {
                if (title.contains("霜") || title.contains("面霜")) {
                  flag = "-1"
                } else {
                  flag = "Y"
                }
              }else if(title.contains("ml") || title.contains("mL") || title.contains("ML")){
                flag="S"
              }else if(title.contains("g")){
                flag="Y"
              }

            } else if (res_str.contains("凝露")) {
              if(key3.contains("乳") && key3.contains("霜")){
                if(title.contains("乳") && title.contains("霜")){
                  if(title.contains("g/ml") || title.contains("g/ML") || title.contains("g/mL")){
                    flag="-1"
                  }else if(title.contains("ml") || title.contains("mL") || title.contains("ML")){
                    flag="Y"
                  }else if(title.contains("g") || title.contains("G")){
                    flag="S"
                  }
                }else if(title.contains("霜")){
                  flag="S"
                } else if(title.contains("乳") || title.contains("液")) {
                  flag = "Y"
                }else if (title.contains("ML") || title.contains("ml") || title.contains("mL")) {
                  flag = "Y"
                } else if (title.contains("g") || title.contains("G")) {
                  flag = "S"
                }
              }else if (key3.contains("霜")) {
                flag = "S"
              } else if (key3.contains("乳") || key3.contains("液")) {
                flag = "Y"
              }else if(key4.contains("乳") && key4.contains("霜")){
                if(title.contains("乳") && title.contains("霜")){
                  if(title.contains("g/ml") || title.contains("g/ML") || title.contains("g/mL")){
                    flag="-1"
                  }else if(title.contains("ml") || title.contains("mL") || title.contains("ML")){
                    flag="Y"
                  }else if(title.contains("g") || title.contains("G")){
                    flag="S"
                  }
                }else if(title.contains("霜")){
                  flag="S"
                } else if(title.contains("乳") || title.contains("液")) {
                  flag = "Y"
                }else if (title.contains("ML") || title.contains("ml") || title.contains("mL")) {
                  flag = "Y"
                } else if (title.contains("g") || title.contains("G")) {
                  flag = "S"
                }
              }else if(key4.contains("霜")){
                flag = "S"
              } else if (key4.contains("乳") || key4.contains("液")) {
                flag = "Y"
              }else if (key2.contains("g/ml") || key2.contains("g/mL")) {
                if (title.contains("乳") || title.contains("液") || title.contains("乳液")) {
                  if (title.contains("霜") || title.contains("面霜")) {
                    flag = "-1"
                  } else {
                    flag = "Y"
                  }
                } else if (title.contains("霜")) {
                  if (title.contains("乳") || title.contains("液") || title.contains("乳液")) {

                    flag = "-1"
                  } else {
                    flag = "Y"
                  }
                }else if (title.contains("g/ml") || title.contains("g/mL")) {
                  if (title.contains("乳") || title.contains("液") || title.contains("乳液")) {
                    if (title.contains("霜") || title.contains("面霜")) {
                      flag = "-1"
                    } else {
                      flag = "Y"
                    }
                  } else if (title.contains("霜")) {
                    if (title.contains("乳") || title.contains("液") || title.contains("乳液")) {
                      flag = "-1"
                    } else {
                      flag = "Y"
                    }
                  }else if(title.contains("ML") || title.contains("ml") || title.contains("mL")){
                    flag="Y"
                  }else if(title.contains("g")){
                    flag="S"
                  }
                } else if (title.contains("g") && title.contains("ml")) {
                  if (title.contains("霜")) {
                    if (title.contains("液") || title.contains("乳")) {
                      flag = "-1"
                    } else {
                      flag = "S"
                    }
                  } else if (title.contains("液") || title.contains("乳")) {
                    if (title.contains("霜")) {
                      flag = "-1"
                    } else {
                      flag = "Y"
                    }
                  }
                } else if (title.contains("g") && title.contains("mL")) {
                  if (title.contains("霜")) {
                    if (title.contains("液") || title.contains("乳")) {
                      flag = "-1"
                    } else {
                      flag = "S"
                    }
                  } else if (title.contains("液") || title.contains("乳")) {
                    if (title.contains("霜")) {
                      flag = "-1"
                    } else {
                      flag = "Y"
                    }
                  }
                } else if (title.contains("ML") || title.contains("ml") || title.contains("mL")) {
                  flag = "Y"
                } else if (title.contains("g") || title.contains("G")) {
                  flag = "S"
                }
              } else if (key2.contains("g") || key2.contains("G")) {
                flag = "S"
              } else if (key2.contains("ml") || key2.contains("mL") || key2.contains("ML")) {
                flag = "Y"
              }else if(title.contains("霜")){
                if (title.contains("液") || title.contains("乳")) {
                  if(title.contains("g/mL")|| title.contains("g/ML")){
                    flag="-1"
                  }else if(title.contains("ml") || title.contains("mL")){
                    flag="Y"
                  }else if(title.contains("g") || title.contains("G")){
                    flag="S"
                  }else{
                    flag="-1"
                  }
                } else {
                  flag = "S"
                }
              }else if (title.contains("液") || title.contains("乳")) {
                if (title.contains("霜")) {
                  if(title.contains("g/mL")|| title.contains("g/ML")){
                    flag="-1"
                  }else if(title.contains("ml") || title.contains("mL")){
                    flag="Y"
                  }else if(title.contains("g") || title.contains("G")){
                    flag="S"
                  }else{
                    flag="-1"
                  }
                } else {
                  flag = "Y"
                }
              }else  if(title.contains("g") && title.contains("mL")) {
                if (title.contains("霜")) {
                  if (title.contains("液") || title.contains("乳")) {
                    flag = "-1"
                  } else {
                    flag = "S"
                  }
                } else if (title.contains("液") || title.contains("乳")) {
                  if (title.contains("霜")) {
                    flag = "-1"
                  } else {
                    flag = "Y"
                  }
                }
              } else if (title.contains("g") && title.contains("ml")) {
                if (title.contains("霜")) {
                  if (title.contains("液") || title.contains("乳")) {
                    flag = "-1"
                  } else {
                    flag = "S"
                  }
                } else if (title.contains("液") || title.contains("乳")) {
                  if (title.contains("霜")) {
                    flag = "-1"
                  } else {
                    flag = "Y"
                  }
                }
              } else if (title.contains("霜")) {
                if (title.contains("乳") || title.contains("液")) {
                  flag = "-1"
                } else {
                  flag = "S"
                }
              } else if (title.contains("乳") || title.contains("液")) {
                if (title.contains("霜") || title.contains("面霜")) {
                  flag = "-1"
                } else {
                  flag = "Y"
                }
              }else if(title.contains("ml") || title.contains("mL") || title.contains("ML")){
                flag="S"
              }else if(title.contains("g")){
                flag="Y"
              }
            } else if (res_str.contains("其他")) {
              if(key3.contains("乳") && key3.contains("霜")){
                if(title.contains("乳") && title.contains("霜")){
                  if(title.contains("g/ml") || title.contains("g/ML") || title.contains("g/mL")){
                    flag="-1"
                  }else if(title.contains("ml") || title.contains("mL") || title.contains("ML")){
                    flag="Y"
                  }else if(title.contains("g") || title.contains("G")){
                    flag="S"
                  }
                }else if(title.contains("霜")){
                  flag="S"
                } else if(title.contains("乳") || title.contains("液")) {
                  flag = "Y"
                }else if (title.contains("ML") || title.contains("ml") || title.contains("mL")) {
                  flag = "Y"
                } else if (title.contains("g") || title.contains("G")) {
                  flag = "S"
                }
              }else if (key3.contains("霜")) {
                flag = "S"
              } else if (key3.contains("乳") || key3.contains("液")) {
                flag = "Y"
              }else if(key4.contains("乳") && key4.contains("霜")){
                if(title.contains("乳") && title.contains("霜")){
                  if(title.contains("g/ml") || title.contains("g/ML") || title.contains("g/mL")){
                    flag="-1"
                  }else if(title.contains("ml") || title.contains("mL") || title.contains("ML")){
                    flag="Y"
                  }else if(title.contains("g") || title.contains("G")){
                    flag="S"
                  }
                }else if(title.contains("霜")){
                  flag="S"
                } else if(title.contains("乳") || title.contains("液")) {
                  flag = "Y"
                }else if (title.contains("ML") || title.contains("ml") || title.contains("mL")) {
                  flag = "Y"
                } else if (title.contains("g") || title.contains("G")) {
                  flag = "S"
                }
              }else if(key4.contains("霜")){
                flag = "S"
              } else if (key4.contains("乳") || key4.contains("液")) {
                flag = "Y"
              }else if (key2.contains("g/ml") || key2.contains("g/mL")) {
                if (title.contains("乳") || title.contains("液") || title.contains("乳液")) {
                  if (title.contains("霜") || title.contains("面霜")) {
                    flag = "-1"
                  } else {
                    flag = "Y"
                  }
                } else if (title.contains("霜")) {
                  if (title.contains("乳") || title.contains("液") || title.contains("乳液")) {

                    flag = "-1"
                  } else {
                    flag = "Y"
                  }
                }else if (title.contains("g/ml") || title.contains("g/mL")) {
                  if (title.contains("乳") || title.contains("液") || title.contains("乳液")) {
                    if (title.contains("霜") || title.contains("面霜")) {
                      flag = "-1"
                    } else {
                      flag = "Y"
                    }
                  } else if (title.contains("霜")) {
                    if (title.contains("乳") || title.contains("液") || title.contains("乳液")) {
                      flag = "-1"
                    } else {
                      flag = "Y"
                    }
                  }else if(title.contains("ML") || title.contains("ml") || title.contains("mL")){
                    flag="Y"
                  }else if(title.contains("g")){
                    flag="S"
                  }
                } else if (title.contains("g") && title.contains("ml")) {
                  if (title.contains("霜")) {
                    if (title.contains("液") || title.contains("乳")) {
                      flag = "-1"
                    } else {
                      flag = "S"
                    }
                  } else if (title.contains("液") || title.contains("乳")) {
                    if (title.contains("霜")) {
                      flag = "-1"
                    } else {
                      flag = "Y"
                    }
                  }
                } else if (title.contains("g") && title.contains("mL")) {
                  if (title.contains("霜")) {
                    if (title.contains("液") || title.contains("乳")) {
                      flag = "-1"
                    } else {
                      flag = "S"
                    }
                  } else if (title.contains("液") || title.contains("乳")) {
                    if (title.contains("霜")) {
                      flag = "-1"
                    } else {
                      flag = "Y"
                    }
                  }
                } else if (title.contains("ML") || title.contains("ml") || title.contains("mL")) {
                  flag = "Y"
                } else if (title.contains("g") || title.contains("G")) {
                  flag = "S"
                }
              } else if (key2.contains("g") || key2.contains("G")) {
                flag = "S"
              } else if (key2.contains("ml") || key2.contains("mL") || key2.contains("ML")) {
                flag = "Y"
              }else if(title.contains("霜")){
                if (title.contains("液") || title.contains("乳")) {
                  if(title.contains("g/mL")|| title.contains("g/ML")){
                    flag="-1"
                  }else if(title.contains("ml") || title.contains("mL")){
                    flag="Y"
                  }else if(title.contains("g") || title.contains("G")){
                    flag="S"
                  }else{
                    flag="-1"
                  }
                } else {
                  flag = "S"
                }
              }else if (title.contains("液") || title.contains("乳")) {
                if (title.contains("霜")) {
                  if(title.contains("g/mL")|| title.contains("g/ML")){
                    flag="-1"
                  }else if(title.contains("ml") || title.contains("mL")){
                    flag="Y"
                  }else if(title.contains("g") || title.contains("G")){
                    flag="S"
                  }else{
                    flag="-1"
                  }
                } else {
                  flag = "Y"
                }
              }else  if(title.contains("g") && title.contains("mL")) {
                if (title.contains("霜")) {
                  if (title.contains("液") || title.contains("乳")) {
                    flag = "-1"
                  } else {
                    flag = "S"
                  }
                } else if (title.contains("液") || title.contains("乳")) {
                  if (title.contains("霜")) {
                    flag = "-1"
                  } else {
                    flag = "Y"
                  }
                }
              } else if (title.contains("g") && title.contains("ml")) {
                if (title.contains("霜")) {
                  if (title.contains("液") || title.contains("乳")) {
                    flag = "-1"
                  } else {
                    flag = "S"
                  }
                } else if (title.contains("液") || title.contains("乳")) {
                  if (title.contains("霜")) {
                    flag = "-1"
                  } else {
                    flag = "Y"
                  }
                }
              } else if (title.contains("霜")) {
                if (title.contains("乳") || title.contains("液")) {
                  flag = "-1"
                } else {
                  flag = "S"
                }
              } else if (title.contains("乳") || title.contains("液")) {
                if (title.contains("霜") || title.contains("面霜")) {
                  flag = "-1"
                } else {
                  flag = "Y"
                }
              }else if(title.contains("ml") || title.contains("mL") || title.contains("ML")){
                flag="S"
              }else if(title.contains("g")){
                flag="Y"
              }
             }else if(title.contains("霜")){
              if (title.contains("液") || title.contains("乳")) {
                  if(title.contains("g/mL")|| title.contains("g/ML")){
                      flag="-1"
                  }else if(title.contains("ml") || title.contains("mL")){
                    flag="Y"
                  }else if(title.contains("g") || title.contains("G")){
                    flag="S"
                  }else{
                    flag="-1"
                  }
              } else {
                flag = "S"
              }
            }else if (title.contains("液") || title.contains("乳")) {
              if (title.contains("霜")) {
                if(title.contains("g/mL")|| title.contains("g/ML")){
                  flag="-1"
                }else if(title.contains("ml") || title.contains("mL")){
                  flag="Y"
                }else if(title.contains("g") || title.contains("G")){
                  flag="S"
                }else{
                  flag="-1"
                }
              } else {
                flag = "Y"
              }
            }else  if(title.contains("g") && title.contains("mL")) {
              if (title.contains("霜")) {
                if (title.contains("液") || title.contains("乳")) {
                  flag = "-1"
                } else {
                  flag = "S"
                }
              } else if (title.contains("液") || title.contains("乳")) {
                if (title.contains("霜")) {
                  flag = "-1"
                } else {
                  flag = "Y"
                }
              }
            } else if (title.contains("g") && title.contains("ml")) {
              if (title.contains("霜")) {
                if (title.contains("液") || title.contains("乳")) {
                  flag = "-1"
                } else {
                  flag = "S"
                }
              } else if (title.contains("液") || title.contains("乳")) {
                if (title.contains("霜")) {
                  flag = "-1"
                } else {
                  flag = "Y"
                }
              }
            } else if (title.contains("霜")) {
              if (title.contains("乳") || title.contains("液")) {
                flag = "-1"
              } else {
                flag = "S"
              }
            } else if (title.contains("乳") || title.contains("液")) {
              if (title.contains("霜") || title.contains("面霜")) {
                flag = "-1"
              } else {
                flag = "Y"
              }
            }else if(title.contains("ml") || title.contains("mL") || title.contains("ML")){
              flag="S"
            }else if(title.contains("g")){
              flag="Y"
            }
          }
        }
      } else if (baser.equals("-1")) {
        if (title.contains("霜")) {
          if (title.contains("液") || title.contains("乳")) {
            flag = "-1"
          } else {
            flag = "S"
          }
        } else if (title.contains("液") || title.contains("乳")) {
          if (title.contains("霜")) {
            flag = "-1"
          } else {
            flag = "Y"
          }
        }else  if(title.contains("g") && title.contains("mL")) {
          if (title.contains("霜")) {
            if (title.contains("液") || title.contains("乳")) {
              flag = "-1"
            } else {
              flag = "S"
            }
          } else if (title.contains("液") || title.contains("乳")) {
            if (title.contains("霜")) {
              flag = "-1"
            } else {
              flag = "Y"
            }
          }
        } else if (title.contains("g") && title.contains("ml")) {
          if (title.contains("霜")) {
            if (title.contains("液") || title.contains("乳")) {
              flag = "-1"
            } else {
              flag = "S"
            }
          } else if (title.contains("液") || title.contains("乳")) {
            if (title.contains("霜")) {
              flag = "-1"
            } else {
              flag = "Y"
            }
          }
        } else if (title.contains("霜")) {
          if (title.contains("乳") || title.contains("液")) {
            flag = "-1"
          } else {
            flag = "S"
          }
        } else if (title.contains("乳") || title.contains("液")) {
          if (title.contains("霜") || title.contains("面霜")) {
            flag = "-1"
          } else {
            flag = "Y"
          }
        }else if(title.contains("ml") || title.contains("mL") || title.contains("ML")){
          flag="S"
        }else if(title.contains("g")){
          flag="Y"
        }
      }
      (good,baser,title,flag)
    })
    // fuyi
    val flagRdd =unit.filter(_._4.equals("-1"))
    // 乳液
    val RS_RDD = unit.map(line=>{
        val good_id = line._1
        val flag = line._4
      (good_id,flag)
    }).filter(!_._2.equals("-1"))

    println(flagRdd.count())

    val unit1 = flagRdd.map(line => {
      val good_id = line._1
      val base_Info = line._2
      val title = line._3
      var flag = "-1"
      if (title.contains("霜")) {
        if (title.contains("液") || title.contains("乳")) {
          if (title.contains("g/ML") || title.contains("g/ml") || title.contains("g/mL")) {
            flag = "-1"
          } else if (title.contains("ml") || title.contains("mL") || title.contains("ML")) {
            flag = "Y"
          } else if (title.contains("G") || title.contains("g")) {
            flag = "S"
          }
        } else {
          flag = "S"
        }
      } else if (title.contains("液") || title.contains("乳")) {
        if (title.contains("霜")) {
          if (title.contains("g/ML") || title.contains("g/ml") || title.contains("g/mL")) {
            flag = "-1"
          } else if (title.contains("ml") || title.contains("mL") || title.contains("ML")) {
            flag = "Y"
          } else if (title.contains("G") || title.contains("g")) {
            flag = "S"
          }
        } else {
          flag = "Y"
        }
      } else if (title.contains("g") && title.contains("mL")) {
        if (title.contains("霜")) {
          if (title.contains("液") || title.contains("乳")) {
            flag = "-1"
          } else {
            flag = "S"
          }
        } else if (title.contains("液") || title.contains("乳")) {
          if (title.contains("霜")) {
            flag = "-1"
          } else {
            flag = "Y"
          }
        }
      } else if (title.contains("g") && title.contains("ml")) {
        if (title.contains("霜")) {
          if (title.contains("液") || title.contains("乳")) {
            flag = "-1"
          } else {
            flag = "S"
          }
        } else if (title.contains("液") || title.contains("乳")) {
          if (title.contains("霜")) {
            flag = "-1"
          } else {
            flag = "Y"
          }
        }
      } else if (title.contains("霜")) {
        if (title.contains("乳") || title.contains("液")) {
          flag = "-1"
        } else {
          flag = "S"
        }
      } else if (title.contains("乳") || title.contains("液")) {
        if (title.contains("霜") || title.contains("面霜")) {
          flag = "-1"
        } else {
          flag = "Y"
        }
      } else if (title.contains("ml") || title.contains("mL") || title.contains("ML")) {
        flag = "S"
      } else if (title.contains("g")) {
        flag = "Y"
      }
      (good_id, flag)
    })
    // fuyi
    val res1 =unit1.filter(_._2.equals("-1"))
    // 乳液
    val res2 = unit1.filter(!_._2.equals("-1"))

    import spark.implicits._

    val df1 = RS_RDD.toDF("good_id","flag")
    val df2 = res2.toDF("good_id","flag")
    val df4 = res1.toDF("good_id","flag")
    val df3 = df1.union(df2).union(df4)
    df3.registerTempTable("ruyetable")

    val third_10019 = spark.read.json(path3)

      .drop("thirdCategoryId","fourthCategoryId")
    third_10019.registerTempTable("third_table")

    val sql1 =
      """
        |select a.*,b.flag from third_table a left join ruyetable b on a.good_id = b.good_id
      """.stripMargin

    val res3 = spark.sql(sql1)
    res3.registerTempTable("flag_table")
    val res4 = spark.sql(
      """
        |select * from flag_table where flag='S'
      """.stripMargin).drop("flag")
      .withColumn("thirdCategoryId",lit("100190103"))
        .withColumn("fourthCategoryId",lit("10019010302"))
    println(res4.count())
     res4.repartition(1).write.json(output_path+s"shuang11"+"/S")

    val res5 = spark.sql(
      """
        |select * from flag_table where flag= "Y"
      """.stripMargin).drop("flag").withColumn("thirdCategoryId",lit("100190103"))
      .withColumn("fourthCategoryId",lit("10019010301"))
    println(res5.count)
   res5.repartition(1).write.json(output_path+s"shuang11"+"/Y")

    val res6 = spark.sql(
      """
        |select * from flag_table where flag= "-1"
      """.stripMargin).drop("flag").withColumn("thirdCategoryId",lit("100190103"))
      .withColumn("fourthCategoryId",lit("10019010399"))
        //.withColumn("")
    println(res6.count()+"===========")

   /* res6.registerTempTable("res6")
    sparksql.sql(
      """
        |select sum(salesAmount),sum(sellCount) from res6
      """.stripMargin).show()*/
    res6.repartition(1).write.json(output_path+"shuang11"+"/Q")
  }

}
